import instance from '../utils/request'
// import axios from 'axios'
import { useTokenStore } from '../stores/token';

//注册
export const userRegisterService = (registerData) => {

    //借助于UrlSearchParams进行传递参数
    const param = new URLSearchParams();
    for(let key in registerData){
        param.append(key,registerData[key])
    }

    return instance.post('/user/register',param)

}

//登录
export const userLoginService = (loginData) => {

    //借助于UrlSearchParams进行传递参数
    const param = new URLSearchParams();
    for(let key in loginData){
        param.append(key,loginData[key])
    }

    return instance.post('/user/login',param)

}

//根据token获取对应用户信息
export const getUserInfoService = (token) => {

    return instance.post('/user/findByToken',null)

}

//获取所有用户信息list
export const getUserListService = () => {

    return instance.post('/user/getAllUsers',null)

}

//更新用户信息
export const updateUserInfoService = (userInfo) => {

    //借助于UrlSearchParams进行传递参数
    const param = new URLSearchParams();
    for(let key in userInfo){
        param.append(key,userInfo[key])
    }

    return instance.post('/user/updateUser',param)

}

//根据手机号删除用户
export const deleteUserService = (phoneNumber) => {

    //借助于UrlSearchParams进行传递参数
    const param = new URLSearchParams();
    param.append('phoneNumber',phoneNumber)

    return instance.post('/user/deleteUserByPhoneNumber',param)

}

export default {
    userRegisterService,
    userLoginService,
    getUserInfoService
}